package com.gitee.wsl.transform.encode.base

import com.gitee.wsl.struct.generator.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals

/**
 * Base62单元测试
 *
 * @author looly
 */
class Base62Test {
    @Test
    fun encodeAndDecodeTest() {
        val a = "伦家是一个非常长的字符串66"
        val encode = Base62.encodeToString(a)
        assertEquals("17vKU8W4JMG8dQF8lk9VNnkdMOeWn4rJMva6F0XsLrrT53iKBnqo", encode)

        val decodeStr = Base62.decodeToString(encode)
        assertEquals(a, decodeStr)
    }

    @Test
    fun encodeAndDecodeInvertedTest() {
        val a = "伦家是一个非常长的字符串66"
        val encode = Base62.encodeInvertedToString(a)
        assertEquals("17Vku8w4jmg8Dqf8LK9vnNKDmoEwN4RjmVA6f0xSlRRt53IkbNQO", encode)

        val decodeStr = Base62.decodeInvertedToString(encode)
        assertEquals(a, decodeStr)
    }

    @Test
    fun encodeAndDecodeRandomTest() {
        val a = Generator.SpecialRandom(Random.nextInt(1000))
        val encode = Base62.encodeToString(a)
        val decodeStr = Base62.decodeToString(encode)
        assertEquals(a, decodeStr)
    }

    @Test
    fun encodeAndDecodeInvertedRandomTest() {
        val a =Generator.SpecialRandom(Random.nextInt(1000))
        //val a = Random.randomString(Random.nextInt(1000))
        val encode = Base62.encodeInvertedToString(a)
        val decodeStr = Base62.decodeInvertedToString(encode)
        assertEquals(a, decodeStr)
    }
}